package com.roc.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.roc.dao.DaoException;
import com.roc.dao.INegotiationDao;
import com.roc.page.BaseSearchCondition;

/**
 * 代付流水DaoImpl
 *
 */
@Repository("negotiationDao")
public class NegotiationDaoImpl extends BaseDaoImpl implements INegotiationDao {

	static Logger logger = LogManager.getLogger(NegotiationDaoImpl.class);

	/**
	 * 根据条件查询
	 * 
	 * @param searchCondition
	 * @return
	 * @throws DaoException
	 */
	@Override
	public List<Object> queryByConditions(BaseSearchCondition searchCondition)
			throws DaoException {
		// TODO Auto-generated method stub
		List<Object> searchRsList = new ArrayList<Object>();
		try {
			String sql = searchCondition.getFullSearchHQL(null);
			Session session = sessionFactory.getCurrentSession();
			Query query = session.createSQLQuery(sql);
			List<Object> params = new ArrayList<Object>();
			params = searchCondition.getParams();
			if (params != null && params.size() > 0) {
				for (int i = 0; i < params.size(); i++)
					query.setParameter(i, params.get(i));
			}
			searchRsList = query.list();
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new DaoException("NegotiationDaoImpl query recordes error", e);
		}
		return searchRsList;
	}

}
